﻿using Abp.Domain.Repositories;
using Camc.Quality.Bop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.TimeSetting
{
    public class ClassSettingAppService : QualityAppServiceBase
    {
        private readonly IRepository<ClassSetting, Guid> _classSettingRepository;

        public ClassSettingAppService(IRepository<ClassSetting, Guid> classSettingRepository
            )
        {
            _classSettingRepository = classSettingRepository;

        }
        /// <summary>
        /// 班别设置查询
        /// </summary>
        /// <param name="isUsed"></param>
        /// <returns></returns>
        public List<ClassSettingDto> GetClassSettingList(int isUsed)
        {
            var classSettingRecord = _classSettingRepository.GetAll();
            if (isUsed ==0 || isUsed ==1)
            {
                classSettingRecord = _classSettingRepository.GetAll().Where(d => d.IsUsed == (IsUsed)isUsed).OrderByDescending(a => a.LastModificationTime);
            }
            var codeFormatRecordDto = ObjectMapper.Map<List<ClassSettingDto>>(classSettingRecord);
            return codeFormatRecordDto;
        }
        /// <summary>
        /// 班别设置表update
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task UpdateClassSetting(ClassSettingDto input)
        {
            var classSetting = await _classSettingRepository.FirstOrDefaultAsync(c => c.Id == input.Id);
            if (classSetting != null)
            {
                classSetting.ClassCode = input.ClassCode;
                classSetting.ClassName = input.ClassName;
                classSetting.ClassDetails = input.ClassDetails;
                classSetting.WorkTime = input.WorkTime;
                classSetting.IsUsed = input.IsUsed;

                await _classSettingRepository.UpdateAsync(classSetting);
            }
        }
    }
}


